// 节流public.js
module.exports = {
  throttleFunc: function throttleFunc(func, marginTime) {
    if (marginTime == undefined || marginTime == null) {
      marginTime = 1700
    }
    let lastTime = null
    return function () {
      let currentTime = + new Date()
      if (currentTime - lastTime > marginTime || !lastTime) {
        func.apply(this, arguments) //将this和参数返回给原函数
        lastTime = currentTime
      }
    }
  },
  // 防抖
  debounceFunc: function debounce(fn, wait = 500) {
    var timer = null;
    return function () {
      var context = this
      var args = arguments
      if (timer) {
        clearTimeout(timer);
        timer = null;
      }
      timer = setTimeout(function () {
        fn.apply(context, args)
      }, wait)
    }
  }
}


